package com.casa.POI.dianping;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;
import org.hibernate.cfg.Configuration;

public class SessionManager {
	
	private static SessionManager instance;
	private static Object lock = new Object();
	private SessionFactory sessionFactory;
	
	protected  SessionManager() {
		Configuration config = new Configuration().configure();
		sessionFactory = config.buildSessionFactory();
	}
	
	public static SessionManager getInstance() {
		if (instance == null) {
			synchronized (lock) {
				if (instance == null) {
					instance = new SessionManager();
				}
			}
		}
		return instance;
	}
	
	public Session openSession() {
		return this.sessionFactory.openSession();
	}
	
	public StatelessSession openStatelessSession() {
		return this.sessionFactory.openStatelessSession();
	}

}
